home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / hf^k-5.dms / in.adf / PhxASS.Lha / Examples / gadgets.asm < prev    next >
Encoding:
Assembly Source File  |  1996-10-11  |  6.5 KB  |  334 lines

  1. **
  2. **    Gadget Example
  3. **
  4.  
  5.     incdir    "include"
  6.     include    "lib/exec.i"        ; library offsets
  7.     include    "lib/intuition.i"
  8.     include    "lib/gadtools.i"
  9.  
  10. **  You should also define an include path for your Commodore **
  11. ** includes or make use of the PHXASSINC environment variable **
  12.     include    "intuition/intuition.i"    ; OS includes
  13.     include    "libraries/gadtools.i"
  14.     include "graphics/gfxbase.i"
  15.     include    "graphics/rastport.i"
  16.     include    "graphics/text.i"
  17.  
  18.  
  19.  
  20.     code
  21.  
  22.  
  23. start:
  24.     bsr    initialize
  25.     beq    1$            ;error during init?
  26.     bsr    main            ;main loop
  27. 1$:    bsr    cleanup            ;free all
  28.     moveq    #0,d0
  29.     rts
  30.  
  31.  
  32. main:
  33.     move.l    GadtoolsBase,a6
  34.     move.l    usrport,a0
  35.     jsr    GT_GetIMsg(a6)        ;fetch next IDCMP-Message
  36.     tst.l    d0
  37.     bne    2$            ;deal with it
  38.     move.l    SysBase,a6
  39.     move.l    usrport,a0        ;process sleeps until next
  40.     jsr    WaitPort(a6)        ; message arrives
  41.     bra    main
  42.  
  43. 2$:    move.l    d0,a1
  44.     move.l    im_Class(a1),d3        ;d2 message's IDCMP-Class
  45.     move.w    im_Code(a1),d2        ;d3 IDCMP-Code
  46.     move.l    im_IAddress(a1),a2    ;a2 object which generated this msg
  47.     jsr    GT_ReplyIMsg(a6)
  48.  
  49.     cmp.l    #IDCMP_CLOSEWINDOW,d3    ;clicked close gadget?
  50.     beq    1$
  51.  
  52. 3$:    cmp.l    #IDCMP_GADGETUP,d3    ;released one of our gadgets?
  53.     bne    4$
  54.     move.w    gg_GadgetID(a2),d0    ;gadget Id
  55.     move.l    gg_SpecialInfo(a2),a0    ;gadget's SpecialInfo structure
  56.     bsr    do_gadget
  57.  
  58. 4$:    bra    main
  59.  
  60. ; place for extensions
  61.  
  62. 1$:    rts
  63.  
  64.  
  65. do_gadget:
  66. ; a2 = pointer to Gadget structure
  67. ; d0 = Id of selected gadget
  68. ; a0 = pointer to gadget's SpecialInfo (for string-, integer gadgets, etc.)
  69.     cmp.w    #MYBUTTONGAD,d0
  70.     bne    1$
  71. ; Button gadget was clicked
  72.     move.l    IntBase,a6
  73.     clr.l    -(sp)
  74.     move.l    sp,a2
  75.     move.l    sp,a2
  76.     move.l    winptr,a0
  77.     lea    easyreq_button,a1
  78.     jsr    EasyRequestArgs(a6)
  79.     addq.l    #4,sp
  80.     bra    3$
  81. 1$:    cmp.w    #MYCHECKBOX,d0
  82.     bne    2$
  83. ; Checkbox gadget was clicked
  84.     move.l    IntBase,a6
  85.     clr.l    -(sp)
  86.     move.l    sp,a2
  87.     move.l    sp,a2
  88.     move.l    winptr,a0
  89.     lea    easyreq_checkbox,a1
  90.     jsr    EasyRequestArgs(a6)
  91.     addq.l    #4,sp
  92.     bra    3$
  93. 2$:    cmp.w    #MYINTEGERGAD,d0
  94.     bne    3$            ;unknown gadget
  95. ; a new value was entered into the Integer gadget
  96.     move.l    IntBase,a6
  97.     move.l    gg_SpecialInfo(a2),a0    ;contrains ptr to StringInfo struct
  98.     move.l    si_LongInt(a0),-(sp)    ;entered integer value
  99.     move.l    sp,a3            ;pass as argument for EasyRequest
  100.     clr.l    -(sp)
  101.     move.l    sp,a2
  102.     move.l    winptr,a0
  103.     lea    easyreq_intgad,a1
  104.     jsr    EasyRequestArgs(a6)
  105.     addq.l    #8,sp
  106. 3$:    rts
  107.  
  108.  
  109. initialize:
  110. ; open all reqiuired libraries, initialize gadgets and
  111. ; open a window on the workbench
  112. ; -> d0 = TRUE: ok, FALSE: error
  113.     move.l    4,a6
  114.     move.l    a6,SysBase
  115.     lea    intname(pc),a1
  116.     moveq    #36,d0
  117.     jsr    OpenLibrary(a6)        ;intuition.library v36
  118.     move.l    d0,IntBase
  119.     beq    1$
  120.     lea    gadtname(pc),a1
  121.     moveq    #36,d0
  122.     jsr    OpenLibrary(a6)        ;gadtools.library v36
  123.     move.l    d0,GadtoolsBase
  124.     beq    1$
  125.  
  126.     lea    gfxname(pc),a1
  127.     moveq    #36,d0            ;graphics.library
  128.     jsr    OpenLibrary(a6)
  129.     tst.l    d0
  130.     beq    1$
  131.     move.l    d0,a1
  132.     lea    gadtxtattr,a5        ;get default font TxtAttr
  133.     move.l    gb_DefaultFont(a1),a0
  134.     move.l    LN_NAME(a0),ta_Name(a5)
  135.     move.l    tf_YSize(a0),ta_YSize(a5)
  136.     move.w    ta_YSize(a5),d6
  137.     addq.w    #6,d6            ;d6 default height for gadgets
  138.     jsr    CloseLibrary(a6)
  139.  
  140.     move.l    IntBase,a6
  141.     sub.l    a0,a0
  142.     jsr    LockPubScreen(a6)    ;lock default public screen
  143.     move.l    d0,pubscreen
  144.     move.l    GadtoolsBase,a6
  145.     move.l    d0,a0
  146.     sub.l    a1,a1
  147.     jsr    GetVisualInfoA(a6)    ;get pointer to screen's VisualInfo
  148.     move.l    d0,vinfo
  149.     beq    1$
  150.     move.l    d0,d7            ;d7 VisualInfo
  151.     
  152.     lea    glist,a0        ;start to create GadTools gadgets
  153.     jsr    CreateContext(a6)
  154.     tst.l    d0
  155.     beq    1$
  156.     move.l    d0,a0
  157.     lea    newbutton,a1
  158.     move.w    d6,gng_Height(a1)
  159.     move.l    d7,gng_VisualInfo(a1)
  160.     move.l    a5,gng_TextAttr(a1)
  161.     sub.l    a2,a2
  162.     moveq    #BUTTON_KIND,d0
  163.     jsr    CreateGadgetA(a6)    ;create Button Gadget
  164.     tst.l    d0
  165.     beq    1$
  166.     move.l    d0,a0
  167.     lea    newcheckbox,a1
  168.     move.l    d7,gng_VisualInfo(a1)
  169.     move.l    a5,gng_TextAttr(a1)
  170.     sub.l    a2,a2
  171.     moveq    #CHECKBOX_KIND,d0
  172.     jsr    CreateGadgetA(a6)    ;create Checkbox Gadget
  173.     tst.l    d0
  174.     beq    1$
  175.     move.l    d0,a0
  176.     lea    newintgad,a1
  177.     move.w    d6,gng_Height(a1)
  178.     move.l    d7,gng_VisualInfo(a1)
  179.     move.l    a5,gng_TextAttr(a1)
  180.     sub.l    a2,a2
  181.     moveq    #INTEGER_KIND,d0
  182.     jsr    CreateGadgetA(a6)    ;create Integer Gadget
  183.     tst.l    d0
  184.     beq    1$
  185.  
  186.     move.l    IntBase,a6
  187.     lea    mywindow,a0        ;open window on public screen
  188.     move.l    glist,nw_FirstGadget(a0)
  189.     jsr    OpenWindow(a6)
  190.     move.l    d0,winptr
  191.     beq    1$
  192.     move.l    d0,a2
  193.     move.l    wd_UserPort(a2),usrport    ;pointer to window's IDCMP-MsgPort
  194.  
  195.     sub.l    a0,a0
  196.     move.l    pubscreen,a1
  197.     jsr    UnlockPubScreen(a6)
  198.     clr.l    pubscreen
  199.  
  200.     move.l    GadtoolsBase,a6
  201.     move.l    winptr,a0
  202.     sub.l    a1,a1
  203.     jsr    GT_RefreshWindow(a6)
  204.  
  205.     moveq    #-1,d0            ;ok, no problems
  206. 1$:    rts
  207.  
  208.  
  209. cleanup:
  210. ; free all allocated resources
  211.     move.l    IntBase,d0
  212.     beq    1$
  213.     move.l    d0,a6
  214.     move.l    winptr,d0
  215.     beq    6$
  216.     move.l    d0,a0
  217.     jsr    CloseWindow(a6)        ;close window
  218. 6$:    move.l    pubscreen,d0
  219.     beq    5$
  220.     sub.l    a0,a0
  221.     move.l    d0,a1
  222.     jsr    UnlockPubScreen(a6)
  223.  
  224. 5$:    move.l    GadtoolsBase,d0
  225.     beq    2$
  226.     move.l    d0,a6
  227.     move.l    vinfo,d0
  228.     beq    4$
  229.     move.l    d0,a0
  230.     jsr    FreeVisualInfo(a6)    ;free screen's VisualInfo
  231. 4$:    move.l    glist,a0
  232.     jsr    FreeGadgets(a6)        ;free GadTools gadgets
  233.  
  234.     move.l    a6,a1
  235.     move.l    SysBase,a6
  236.     jsr    CloseLibrary(a6)    ;closse gadtools.library
  237. 2$:    move.l    SysBase,a6
  238.     move.l    IntBase,a1
  239.     jsr    CloseLibrary(a6)    ;close intuition.library
  240. 1$:    rts
  241.  
  242.  
  243. intname:
  244.     dc.b    "intuition.library",0
  245. gadtname:
  246.     dc.b    "gadtools.library",0
  247. gfxname:
  248.     dc.b    "graphics.library",0
  249.  
  250.  
  251.  
  252.     data
  253.  
  254.  
  255. mywindow:                ;refer to: struct NewWindow
  256.     dc.w    16,16,256,128
  257.     dc.b    0,1
  258. ; we're waiting for these IDCMP messages
  259.     dc.l    IDCMP_CLOSEWINDOW|IDCMP_GADGETUP
  260. ; window flags
  261.     dc.l    WFLG_ACTIVATE|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET
  262.     dc.l    0,0,win_title,0,0
  263.     dc.w    128,32,-1,-1,PUBLICSCREEN
  264. win_title:
  265.     dc.b    "Gadget Example",0
  266.     even
  267.  
  268. ; NewGadget strucures, refer to: libraries/gadtools.i
  269. newbutton:
  270.     dc.w    16,32,80,0
  271.     dc.l    1$,0
  272.     dc.w    MYBUTTONGAD
  273.     dc.l    PLACETEXT_IN,0,0
  274. 1$:    dc.b    "Button",0
  275.     even
  276. newcheckbox:
  277.     dc.w    160,32,20,20
  278.     dc.l    1$,0
  279.     dc.w    MYCHECKBOX
  280.     dc.l    PLACETEXT_BELOW,0,0
  281. 1$:    dc.b    "Checkbox",0
  282.     even
  283. newintgad:
  284.     dc.w    100,80,128,0
  285.     dc.l    1$,0
  286.     dc.w    MYINTEGERGAD
  287.     dc.l    PLACETEXT_LEFT,0,0
  288. 1$:    dc.b    "Number:",0
  289.     even
  290. ; Gadget-Ids
  291. MYBUTTONGAD    equ    1
  292. MYCHECKBOX    equ    2
  293. MYINTEGERGAD    equ    3
  294.  
  295. easyreq_intgad:
  296.     dc.l    EasyStruct_SIZEOF,0,1$,2$,3$
  297. 1$:    dc.b    "Integer Gadget",0
  298. 2$:    dc.b    "The number %ld\n"
  299.     dc.b    "was just entered.",0
  300. 3$:    dc.b    "Indeed",0
  301.     even
  302. easyreq_button:
  303.     dc.l    EasyStruct_SIZEOF,0,1$,2$,3$
  304. 1$:    dc.b    "Button Gadget",0
  305. 2$:    dc.b    "The button gadget\n"
  306.     dc.b    "was just released.",0
  307. 3$:    dc.b    "That's true",0
  308.     even
  309. easyreq_checkbox:
  310.     dc.l    EasyStruct_SIZEOF,0,1$,2$,3$
  311. 1$:    dc.b    "Checkbox Gadget",0
  312. 2$:    dc.b    "The checkbox gadget\n"
  313.     dc.b    "has been clicked.",0
  314. 3$:    dc.b    "Ok",0
  315.     even
  316.  
  317.  
  318.  
  319.     bss
  320.  
  321.  
  322. SysBase:    ds.l    1
  323. IntBase:    ds.l    1
  324. GadtoolsBase:    ds.l    1
  325. pubscreen:    ds.l    1        ; default public screen
  326. winptr:        ds.l    1
  327. usrport:    ds.l    1
  328. vinfo:        ds.l    1
  329. glist:        ds.l    1        ; gadget list
  330. gadtxtattr:    ds.b    ta_SIZEOF     ; TextAttr structure for gadget's font
  331.  
  332.  
  333.     end
  334.